package pro.shushi.pamirs.hr.core.manager;

import org.springframework.stereotype.Component;
import pro.shushi.pamirs.framework.connectors.data.api.datasource.DsHintApi;
import pro.shushi.pamirs.hr.api.model.org.Employee;
import pro.shushi.pamirs.meta.annotation.fun.extern.Slf4j;
import pro.shushi.pamirs.meta.api.session.PamirsSession;
import pro.shushi.pamirs.meta.common.spring.BeanDefinitionUtils;
import pro.shushi.pamirs.hr.core.mapper.EmployeeMapper;

import java.util.List;
import java.util.Map;

/**
 * 示例代码-调用SQL语句
 * @author shushi
 */
@Slf4j
@Component
public class CustomSqlManager {

    public List<Map<String, Object>> customSqlEmployees() {
        //指定在Employee对应的datasource中执行该sql的mapper
        try (DsHintApi dsHint = DsHintApi.model(Employee.MODEL_MODEL)) {
            String EmployeeTable = PamirsSession.getContext().getModelCache().get(Employee.MODEL_MODEL).getTable();
            EmployeeMapper EmployeeMapper = BeanDefinitionUtils.getBean(EmployeeMapper.class);
            List<Map<String, Object>> dataList = EmployeeMapper.groupByepartmentCode(EmployeeTable);
            return dataList;
        }
    }
}
